package com.wfc.servlet.user;

import com.wfc.entity.User;
import com.wfc.service.UserService;
import com.wfc.service.serviceImpl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/success")
public class SuccServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String pass1=req.getParameter("pass1");
        String pass2=req.getParameter("pass2");
        String username=req.getParameter("username");
        UserService userService = new UserServiceImpl();
        User user = new User();
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter printWriter=resp.getWriter();
        String mag="";
        String name1=user.getUsername();
        if (pass1.equals(pass2)){
            user.setPassword(pass1);
            user.setUsername(username);

            if (userService.updateUser(user)){
                mag="1";

            }
        }else {
            mag="0";
        }
        printWriter.println(mag);


        printWriter.flush();
        printWriter.close();
    }
}
